package cate.game.role.res.guild.po.member;

import cate.common.table.d.GDFunc;
import cate.common.table.d.GDGuild;
import cate.game.GameBody;
import cate.game.role.Role;
import cate.game.role.res.guild.GuildFuncBase;
import cate.game.role.res.guild.msg.member.GuildMemberLogResp;
import cate.game.role.res.guild.po.GuildLogDetailPO;
import cate.game.role.res.guild.po.GuildPO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

public class GuildMemberLogPO extends GuildFuncBase {
    @NoteField(value = "公会日志列表")
    public List<GuildLogDetailPO> list;


    @Override
    public void initialize(GuildPO guild) {
        super.initialize(guild);
        if (list == null) {
            list = new ArrayList<>();
        }
    }

    /**
     * 添加公会日志
     */
    @JsonIgnore
    public void addLog(GameBody game, GuildLogDetailPO log) {
        if (list.size() >= GDGuild.member.LOG_NUM_MAX) {
            list.remove(list.size() - 1);
        }
        list.add(0, log);
        // 通知在线玩家有新的日志
        for (Role role : getFuncDependent().guild.member.getOnlineRole()) {
            log.noticeUpdate(role, getFuncId());
        }
    }

    /**
     * 公会日志列表通知
     */
    @JsonIgnore
    public void noticeUpdate(Role role) {
        role.sendNow(new GuildMemberLogResp(this));
    }

    @Override
    public int getFuncId() {
        return GDFunc.GuildFunc.MEMBER;
    }

}
